using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MKDS_Course_Editor
{
    public partial class SpecialPictureBox : PictureBox
    {
        public event EventHandler Selection;
        bool selected;
        Point PanelMouseDownLocation;
        PictureBox p = new PictureBox();
        public SpecialPictureBox()
        {
            p.Image = Properties.Resources.arrow_move;
            p.Visible = false;
            p.SizeMode = PictureBoxSizeMode.AutoSize;
            p.BackColor = Color.White;
            p.MouseDown += new MouseEventHandler(p_MouseDown);
            p.MouseMove += new MouseEventHandler(p_MouseMove);
            p.Cursor = Cursors.SizeAll;
            this.Controls.Add(p);
        }
        void p_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                this.Left += e.X - PanelMouseDownLocation.X;
                this.Top += e.Y - PanelMouseDownLocation.Y;
            }
        }

        void p_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                PanelMouseDownLocation = e.Location;
            }
        }
        public bool Selected
        {
            get { return selected; }
            set { selected = value; this.Invalidate(); if (Selection != null && value == true) { Selection(this, new EventArgs()); } }
        }
        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);
            if (selected)
            {
                pe.Graphics.DrawLines(new Pen(new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.SmallCheckerBoard, Color.Black, Color.White)), new Point[] { new Point(0, 0), new Point(this.Width - 1, 0), new Point(this.Width - 1, this.Height - 1), new Point(0, this.Height - 1), new Point(0, 0) });
                p.Visible = true;
            }
            else
            {
                p.Visible = false;
            }
        }
    }
    public partial class SpecialPanel : Panel
    {
        public event EventHandler Selection;
        bool selected;
        Point PanelMouseDownLocation;
        PictureBox p = new PictureBox();
        public SpecialPanel()
        {
            p.Image = Properties.Resources.arrow_move;
            p.Visible = false;
            p.SizeMode = PictureBoxSizeMode.AutoSize;
            p.BackColor = Color.White;
            p.MouseDown += new MouseEventHandler(p_MouseDown);
            p.MouseMove += new MouseEventHandler(p_MouseMove);
            p.Cursor = Cursors.SizeAll;
            this.Controls.Add(p);
        }
        void p_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                this.Left += e.X - PanelMouseDownLocation.X;
                this.Top += e.Y - PanelMouseDownLocation.Y;
            }
        }

        void p_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                PanelMouseDownLocation = e.Location;
            }
        }
        public bool Selected
        {
            get { return selected; }
            set { selected = value; this.Invalidate(); if (Selection != null && value == true) { Selection(this, new EventArgs()); } }
        }
        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);
            if (selected)
            {
                pe.Graphics.DrawLines(new Pen(new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.SmallCheckerBoard, Color.Black, Color.White)), new Point[] { new Point(0, 0), new Point(this.Width - 1, 0), new Point(this.Width - 1, this.Height - 1), new Point(0, this.Height - 1), new Point(0, 0) });
                //pe.Graphics.DrawRectangle(new Pen(new SolidBrush(Color.Black)), (this.Width/2)-3, 0, 6, 6);
                //pe.Graphics.FillRectangle(new SolidBrush(Color.White), (this.Width / 2) - 2, 1, 4, 4);
                //pe.Graphics.DrawRectangle(new Pen(new SolidBrush(Color.Black)), 0, (this.Height / 2) - 3, 6, 6);
                //pe.Graphics.FillRectangle(new SolidBrush(Color.White), 1, (this.Height / 2) - 2, 4, 4);
                p.Visible = true;
            }
            else
            {
                p.Visible = false;
            }
        }
    }
}
